/**
 * Class Config
 * is used to parse he config data form config.json or form localstorage
 */
Config = (function() {
	/**
	 * Config constructor
	 * @constructor
	 */
    function Config() {
        this.local = new Local('config');
    }
	/**
	 * Load config from config.json or localstorage
	 * @param [update] {Boolean} update form ajax or not
	 */
    Config.prototype.load = function(update) {
        var _this = this;
        this.data = this.local.get();
        if (update || !this.data) {
            this.ajax = new Ajax();
            this.ajax.setOnSuccessListener(function(data) {
                if (data.status === "success") {
                    _this.local.set(_this.data = data.data);
                }
				if(_this.loadListener) _this.loadListener.call(this);
            });
            this.ajax.open("config.json");
            this.ajax.send();
        } else {
			if(_this.loadListener) _this.loadListener.call(this);
        }
    };
	/**
	 * Set On load listener
	 * @param listener {Function} load listener
	 */
    Config.prototype.setOnLoadListener = function(listener) {
		if(!(listener instanceof Function)) throw "listener is not a Function";
		this.loadListener = listener;
	};

    return Config;

})();
